package com.seecode.Adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.seecode.R;
import com.seecode.UnitClass.FileClass;

import java.util.List;
/**
 * Created by Administrator on 2017/10/21.
 */

public class FileAdapter extends ArrayAdapter<FileClass> {
    private int resourceId;

    public FileAdapter(Context context, int textViewResourceId,
    List<FileClass> objects) {
        super(context, textViewResourceId, objects);
        resourceId = textViewResourceId;
    }


    public View getView(int position,  View convertView,  ViewGroup parent) {
        FileClass fileClass = getItem(position); //
        View view;
        ViewHolder viewHolder;
        if(convertView==null) {
            view = LayoutInflater.from(getContext()).inflate(resourceId, parent, false);
            // viewHolder = new ViewHolder();
            viewHolder=new ViewHolder();

            viewHolder.fileImage = (ImageView) view.findViewById(R.id.file_image);
            viewHolder.fileName = (TextView) view.findViewById(R.id.file_name);
            viewHolder.fileInfo = (TextView) view.findViewById(R.id.file_info);
            view.setTag(viewHolder);
        }else{
            view=convertView;
            viewHolder=(ViewHolder)view.getTag();
        }
        //viewHOlderInter 2 ele is view 2 inter element
        viewHolder.fileImage.setImageResource(fileClass.getImageId());
        viewHolder.fileName.setText(fileClass.getName());
        viewHolder.fileInfo.setText(fileClass.getInfo());
        return view;
    }
    class ViewHolder{

        ImageView fileImage;
        TextView fileName;
        TextView fileInfo;
    }
}
